package com.yjc.hire.work.controller;

import com.yjc.hire.grace.result.GraceJSONResult;
import com.yjc.hire.grace.result.ResponseStatusEnum;
import com.yjc.hire.work.service.SysParamsService;
import com.yjc.hire.work.vo.SysParamsVO;
import com.yjc.pojo.SysParams;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * </p>
 *
 * @author jcyin
 * @since 2025/8/25
 * </p>
 */

@RestController
@RequestMapping("sys")
public class SysParamsController {

    @Autowired
    private SysParamsService sysParamsService;

    @GetMapping("modifyMaxRefreshCount")
    public GraceJSONResult modifyMaxRefreshCount(Integer maxRefreshCount,Integer version){
        if (maxRefreshCount==null || maxRefreshCount< 1){
            return GraceJSONResult.errorCustom(ResponseStatusEnum.SYSTEM_PARAMS_SETTINGS_ERROR);
        }
        sysParamsService.updateSysParams(maxRefreshCount,version);
        return GraceJSONResult.ok();
    }

    @PostMapping("getSysParams")
    public GraceJSONResult getSysParams(){
        SysParams sysParams = sysParamsService.getSysParams();
        SysParamsVO vo = new SysParamsVO();
        BeanUtils.copyProperties(sysParams,vo);
        vo.setVersion(0);
        return GraceJSONResult.ok(vo);
    }
}
